package com.pointcircle.core.web;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.pointcircle.core.JpaBaseEntity;

public interface IFindByIdsRest<T extends JpaBaseEntity<ID>, ID extends Serializable, 
	EV extends EntityVo<T, ID>> 
	extends IRest<T, ID, EV> {

	@GetMapping("/findByIds")
	default RestResponseList findByIds(@RequestParam("ids") List<ID> ids) {
		List<T> entities = getRepository().findAllById(ids);
		RestResponseList response = new RestResponseList();
		response.setSuccess(true);
		List<EV> list = new LinkedList<EV>();
		for(T entity : entities) {
			list.add(this.generateEntityVo(entity));
		}
		response.setList(list);
		return response;
	}
}
